<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>药品扫码查询</title>
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/hplus/js/plugins/sweetalert/sweetalert2.min.css">
</head>			

<style type="text/css">				
blockquote {
   border-left:0.4em solid #17B091;
   font-size:17px;
   font-color:#333333;			
}

span:hover{
    color: #17B091;
}

</style>

<body class="white-bg">

        <div class="col-sm-12 text-center" style="padding-top:20px;padding-bottom:20px;">
           <div class="col-sm-1 text-center">
           </div>
           <div class="col-sm-7 text-center">
                 <input type="text" id="barCode" placeholder="请填写条形码数字或使用扫码枪扫描药品条形码查询药品信息" class="input form-control" id="modelName" >    	
           </div>  
           <div class="col-sm-1 text-center">										
            <span class="input-group-btn">
                 <button style="width:80px;" type="button" class="btn btn btn-primary" onclick="searchDrug();"> Enter</button>
            </span>
            </div>
           <div class="col-sm-1 text-center">						
            <span class="input-group-btn">
                 <button style="width:80px;" type="button" class="btn btn btn-primary" onclick="delDrugInfo();"> Del-清空</button>
            </span>
            </div>			
            <div class="col-sm-1 text-center">
            <span class="input-group-btn">
            	 <shiro:hasPermission name="drugs_inquiries:correct">
                 <button style="width:80px;display:none;" id="jcBtn" type="button" class="btn btn btn-danger" onclick="errorCorrection();"> 纠错</button>
            	 </shiro:hasPermission>
            </span>
            </div>
            <div class="col-sm-1 text-center">
           </div>
            
        </div>
        
        <!-- 药品基本信息-->
        <div id="drugInfo" style="display:none;">
        
        <div class="col-sm-12 ">			
        <div class="col-sm-11" style="padding-left:85px;">		
        <span id="error_show" style="color:red;display:none;"> 数据可能有误，请在修复后参考</span>
        </div>	
        
		<div class="col-sm-6" style="padding-left:0;padding-top:20px;">
		<div class="form-group" >
		<label class="col-sm-4 control-label text-right">商品名称：</label>
		<div class="col-sm-8">			
		    <input id="goods_name" name="" disabled = 'disabled' class="form-control" placeholder="" type="text"><span class="help-block m-b-none"></span>
		</div>	
		</div>
		<div class="form-group">				
		<label class="col-sm-4 control-label text-right">产品规格：</label>
		<div class="col-sm-8">			
		    <input id="specifications" name="" disabled = 'disabled' class="form-control" placeholder="" type="text"><span class="help-block m-b-none"></span>
		</div>	
		</div>
		<div class="form-group">		
		<label class="col-sm-4 control-label text-right">商品编号：</label>
		<div class="col-sm-8">			
		    <input id="goods_number" name="" disabled = 'disabled' class="form-control" placeholder="" type="text"><span class="help-block m-b-none"></span>
		</div>		
		</div>
        </div>
        <!-- 条形码 -->
        <input id="bar_code" style="display:none;"></input>
        <!-- 商品id -->
        <input id="id" style="display:none;"></input>
        
        <div class="col-sm-5" style="padding-left:0;padding-top:20px;">
		<div class="form-group" >
		<label class="col-sm-4 control-label text-right">通用名称：</label>
		<div class="col-sm-8">			
		    <input id="general_name" name="" disabled = 'disabled'  class="form-control" placeholder="" type="text"><span class="help-block m-b-none"></span>
		</div>	
		</div>
		<div class="form-group">				
		<label class="col-sm-4 control-label text-right" >批准文号：</label>
		<div class="col-sm-8">						
		    <input id="approval_number" name="" disabled = 'disabled'  class="form-control" placeholder="" type="text"><span class="help-block m-b-none"></span>
		</div>	
		
		</div>
	    <!-- 占位 -->
		<div class="form-group">				
		<label class="col-sm-4 control-label text-right" ></label>
		<div class="col-sm-8">						
		    <p class="form-control-static"></p><span class="help-block m-b-none"></span>
		</div>	
		</div>
        </div>		
        
        <div class="col-sm-12" style="padding-left:0;">								
		<div class="form-group">				
		<label class="col-sm-2 control-label text-right" >用法用量：</label>
		<div class="col-sm-9">						
		    <input id="usage_dosage" disabled = 'disabled'  name="" class="form-control" placeholder="" type="text"><span class="help-block m-b-none"></span>
		</div>	
		</div>		
        </div>		
        
        <div class="col-sm-12" style="padding-left:0;">								
		<div class="form-group">				
		<label class="col-sm-2 control-label text-right" >疗程周期：</label>
		<div class="col-sm-9">						
		    <input id="course_cycle" disabled = 'disabled'  name="" class="form-control" placeholder="" type="text"><span class="help-block m-b-none"></span>
		</div>			
		</div>
        </div>					
        
        
        <div class="col-sm-6" style="padding-left:0;">
		<div class="form-group">		
		<label class="col-sm-4 control-label text-right">适应症：</label>
		<div class="col-sm-8">			
		    <textarea id="adaptation_symptoms" name="" disabled = 'disabled'  style="height:110px;" class="form-control" placeholder="" type="text"></textarea><span class="help-block m-b-none"></span>							
		</div>			
		</div>
        </div>
        			
        <div class="col-sm-5" style="padding-left:0;">
		<div class="form-group">		
		<label class="col-sm-4 control-label text-right">禁忌：</label>
		<div class="col-sm-8">			
		    <textarea id="taboo" name="" disabled = 'disabled'  style="height:110px;" class="form-control" placeholder="" type="text"></textarea><span class="help-block m-b-none"></span>							
		</div>			
		</div>
        </div>				
        
        <!-- 
        <div class="col-sm-12" style="padding-left:30;">		
         <blockquote style="margin-top:0px;">药品详情</blockquote> 
        </div>	
         -->
			<div class="tabs-container col-sm-12">
			<div class="col-sm-1" >
			</div>
			<div class="col-sm-10" >
            <ul class="nav nav-tabs" id="menuTabCrm">
                <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 不良反应</a></li>
                <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="true"> 注意事项</a></li>
                <li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="true"> 药品成分</a></li>
            </ul>							
		    <div class="tab-content">							
            <div id="tab-1" class="tab-pane active">
                <textarea id="adverse_reaction" name="" disabled = 'disabled' style="height:200px;" class="form-control" placeholder="" type="text"></textarea>
            </div>
            <div id="tab-2" class="tab-pane">			
                <textarea id="matters_attention" name="" disabled = 'disabled' style="height:200px;" class="form-control" placeholder="" type="text"></textarea>
            </div>
            <div id="tab-3" class="tab-pane">
                <textarea id="component" name="" disabled = 'disabled' style="height:200px;" class="form-control" placeholder="" type="text"></textarea>
            </div>	
            </div>		
            </div>
            </div>
		</div>
		</div>
		
		<!-- 默认展示页 -->
		<div id="defaultImage" >
		<div style="padding-top:100px;padding-left:30px;text-align:center;">				
		<h3><strong>通过了解药品的用法用量、疗程周期，有助于对药品的销售哦~快扫描药品条形码了解一下吧~</strong></h3>
		</div>
		
		<!-- 图片展示 -->			
		<div style="padding-top:60px;text-align:center;">			
        <img src="<%=path%>/images/marketing/drugScanAddNew.png" width="300px" height="250px"/>
		</div>
		</div>
    </div>

    <script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
	<script src="<%=path%>/js/merchant/jquery.ui.widget.js"></script>
	<script src="<%=path%>/js/merchant/jquery.fileupload.js"></script>						
	<script src="<%=path%>/hplus/js/demo/distpicker.js"></script>
	<!-- 弹窗插件 -->
	<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
    <script type="text/javascript">

    $(function(){
    	document.getElementById('barCode').focus();
    	
    	/*文本框获得焦点时，自动选中内容*/
    	$("#barCode").bind('focus',function(){
    	$(this).select();
    	});
    		
    });
    
    //标记是否可以进行纠错 1可以，0不可以
    var sfjc = 0;
    //查询药品基础信息
    function searchDrug(){
    	//获取输入框的条形码
    	var barCode = $("#barCode").val();
    	if(trim(barCode) == ""){
			swal({title: "请使用扫码枪扫描条形码！",
				html: "",
				type: 'warning'
				}
			).then(function () {
	    		document.getElementById('barCode').focus();
			});
		
    		sfjc = 0;
    		return;
    	}
  		$.ajax({
			  url: "${pageContext.request.contextPath}/drugScan/ajaxGetDataByDrugScan",
			  type: "POST",
			  async: false,
			  data:{"barCode":barCode},
			  dataType: "json",
			  success: function(data){
				  if(data.status == 200){
					  var data = data.data;
					  if(data.courseCycle == 1){
						  $("#error_show").show();
					  }else{
						  $("#error_show").hide();
					  }
					  $("#goods_name ").val(data.goodsName);
					  $("#specifications ").val(data.specifications);
					  $("#goods_number ").val(data.goodsNumber);
					  $("#general_name ").val(data.generalName);
					  $("#approval_number ").val(data.approvalNumber);
					  $("#usage_dosage ").val(data.usageDosage);
					  $("#course_cycle ").val(data.courseCycle);
					  $("#adaptation_symptoms ").val(data.adaptationSymptoms);
					  $("#taboo").val(data.taboo);
					  $("#adverse_reaction").val(data.adverseReaction);
					  $("#matters_attention").val(data.mattersAttention);
					  $("#component").val(data.component);
					  $("#bar_code").val(data.barCode);
					  $("#id").val(data.id);
				      //显示表格基础信息
				      $("#drugInfo").show();
				      $("#defaultImage").hide();
				      sfjc = 1;
				      $("#jcBtn").show();
				      $("#barCode").select();
				      document.getElementById('barCode').focus();
				   }else if(data.status == 201){
					  swal("","未查询到对应的商品信息！", "warning");
					  $("#goods_name ").val("");
					  $("#specifications ").val("");
					  $("#goods_number ").val("");
					  $("#general_name ").val("");
					  $("#approval_number ").val("");
					  $("#usage_dosage ").val("");
					  $("#course_cycle ").val("");
					  $("#adaptation_symptoms ").val("");
					  $("#taboo").val("");
					  $("#adverse_reaction").val("");
					  $("#matters_attention").val("");
					  $("#component").val("");
					  $("#bar_code").val(data.bar_code);
					  $("#id").val(data.id);
					  $("#drugInfo").hide();
					  $("#defaultImage").show(); 
					  sfjc = 0;
					  $("#barCode").select();
					  document.getElementById('barCode').focus();
					}else if(data.courseCycle == "20028"){
						//跳转到登陆页
						window.location.href="<%=path%>";
					}
			   }
			 }); 
    }
    
    //隐藏默认展示页面
    function delDrugInfo(){		
    	$("#barCode").val("");
		$("#goods_name ").val("");
		$("#specifications ").val("");
		$("#goods_number ").val("");
		$("#general_name ").val("");
		$("#approval_number ").val("");
		$("#usage_dosage ").val("");
		$("#course_cycle ").val("");
		$("#adaptation_symptoms ").val("");
		$("#taboo").val("");
		$("#adverse_reaction").val("");					
		$("#matters_attention").val("");
		$("#component").val("");
		$("#bar_code").val("");
		$("#id").val("");
    	$("#drugInfo").hide();
    	$("#defaultImage").show();
	    $("#jcBtn").hide();
    	document.getElementById('barCode').focus();						
    }		
    
    //纠错方法
    function errorCorrection(){
    	if(sfjc == 0){
			swal({title: "请使用扫码枪扫描条形码！",
				html: "",
				type: 'warning'
				}
			).then(function () {
	    		document.getElementById('barCode').focus();
			});
    	}else{
    		$.ajax({
  			  url: "${pageContext.request.contextPath}/drugScan/ajaxErrorCorrect",
  			  type: "POST",
  			  async: false,
  			  data:{"id":$("#id").val()},
  			  dataType: "json",
  			  success: function(data){
  				  if(data.status == 200){
  					swal({title: "纠错成功！",
  						html: "",
  						type: 'success'
  						}
  					).then(function () {
  					  	$("#error_show").show();
  			    		document.getElementById('barCode').focus();
  					});
  				   }else if(data.status == 200){
    				swal({title: "纠错失败！",
      						html: "",
      						type: 'error'
      						}
      					).then(function () {
      			    	document.getElementById('barCode').focus();
      				});
  					}else if(data.status == 200){
					//跳转到登陆页
					window.location.href="<%=path%>";
					}
  			   }
  			 }); 
    	}
    }
    

    $(document).keyup(function (e) {//捕获文档对象的按键弹起事件  
        //回车事件(扫码后会自动触发)
        if (e.keyCode == 13) {//按键信息对象以参数的形式传递进来了  
        	searchDrug();
        }
    	//退格事件
        if (e.keyCode == 8) {//按键信息对象以参数的形式传递进来了  
        	delDrugInfo();
        } 
    });  
    

    
    //去掉字符串旁边的空格
    function trim(str){ 
     return str.replace(/(^\s*)|(\s*$)/g, ""); 
    }

    </script>
</body>
</html>
